package com.x.Servlet_10_三大域对象;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * ClassName: Servlet2
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.08.29 17:10
 */

@WebServlet("/DataTrans2")
public class Servlet2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求域数据
        String message1 = (String) req.getAttribute("k-request");
        System.out.println("请求域数据: "+message1);

        //获取会话域数据
        String message2 = (String) req.getSession().getAttribute("k-session");
        System.out.println("会话域数据: "+message2);

        //获取应用域数据
        String message3 = (String) req.getServletContext().getAttribute("k-app");
        System.out.println("应用域数据: "+message3);
    }
}
